﻿using log4net;
using System;
using TruckScale.ViewModels;

namespace TruckScale.Helpers
{
  public class LogHelper
  {

    public enum LogLevel
    {
      Debug, Info, Warn, Error
    }

    public enum LogType
    {
      OperationLogger, HardwareLogger, UploadLogger
    }

    public static void SetLog(string logstr, LogType logType, LogLevel logLevel = LogLevel.Info)
    {
      string loggerName;

      switch (logType)
      {
        case LogType.OperationLogger:
          loggerName = "OperationLogger";
          break;
        case LogType.HardwareLogger:
          loggerName = "HardwareLogger";
          break;
        case LogType.UploadLogger:
          loggerName = "UploadLogger";
          break;
        default:
          loggerName = "DefaultLogger";
          break;
      }

      var logger = LogManager.GetLogger(loggerName);

      switch (logLevel)
      {
        case LogLevel.Debug:
          logger.Debug(logstr);
          break;
        case LogLevel.Info:
          logger.Info(logstr);
          break;
        case LogLevel.Warn:
          logger.Warn(logstr);
          break;
        case LogLevel.Error:
          logger.Error(logstr);
          break;
        default:
          break;
      }

      if (logLevel != LogLevel.Debug)
      {
        App.Current.Dispatcher.Invoke(() => MainViewModel.Logs.Add(DateTime.Now.ToString() + " " + logstr));
      }
    }
  }
}
